﻿using IM.Easy.Core.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IM.Easy.Core.Result
{
    public class ApiBulkResult : ApiResult<BlukResult>
    {
        public override ResultCode Code
        {
            get
            {
                return ResultCode.Success;
            }
        }
        public override bool IsSuccess
        {
            get
            {
                return Data.FailureCount == 0;
            }
        }
        //public int SuccessCount { get; set; }
        //public int FailureCount { get; set; }
        //public List<BulkError<object>> Errors { get; set; } = [];
        //public string Message { get; set; }

        //public void AddFailure<T>(T item, string errorMessage)
        //{
        //    Errors.Add(new BulkError<object> { Item = item, ErrorMessage = errorMessage });
        //    FailureCount++;
        //}

        //public void AddSuccess()
        //{
        //    SuccessCount++;
        //}

    }

    /// <summary>
    /// 批量操作返回体
    /// </summary>
    public class BlukResult
    {
        public int SuccessCount { get; set; }
        public int FailureCount { get; set; }
        public List<BulkError<object>> Errors { get; set; } = [];
        public void AddFailure<T>(T item, string errorMessage)
        {
            Errors.Add(new BulkError<object> { Item = item, ErrorMessage = errorMessage });
            FailureCount++;
        }
        public void AddSuccess()
        {
            SuccessCount++;
        }
    }

    public class BulkError<T>
    {
        public T Item { get; set; }
        public string ErrorMessage { get; set; }
    }
}
